package action;

import Impl.userDaoImpl;
import entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "ShowUser")
public class ShowUser extends HttpServlet {
    userDaoImpl userDao=new userDaoImpl();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("--------正在执行ShowUser--------");
        request.setCharacterEncoding("utf-8");
        int pageNow = 0;
        if(request.getParameter("pageNow") == null) {
            pageNow = 1;
        }else {
            pageNow = Integer.parseInt(request.getParameter("pageNow"));
        }
        //       获取所有用户信息
        List<User> users =userDao.findUserByPages(pageNow);
        List<User> userList=userDao.findAllUser();
        int allcount = userList.size();
        int allpage;
        if(allcount % 5 == 0){
            allpage=allcount / 5;
        }
        else{
            allpage=allcount / 5 + 1;
        }
        request.setAttribute("allcount",allcount);
        request.setAttribute("allpage", allpage);
        request.setAttribute("pageNow", pageNow);
        request.setAttribute("userlist",users);
        request.getRequestDispatcher("/member-list.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
